package com.jinzhi.api.controller.aunt;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jinzhi.api.service.AuntHomeService;
import com.jinzhi.common.constants.ConstMessages;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzapi.domain.UserDO;
import com.jinzhi.jzweb.domain.*;
import com.jinzhi.jzweb.domain.vo.AuntUserVO;
import com.jinzhi.jzweb.service.JazMessageService;
import com.jinzhi.jzweb.service.JazSysBannerService;
import com.jinzhi.jzweb.service.JazSysProjectService;
import com.jinzhi.jzweb.service.JazUserOrderService;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: mcf
 * @CreateTime: 2024/05/10
 * @Description: 阿姨端首页Controller
 */
@Controller
@RequestMapping("/api/auntHome")
@Api(value = "阿姨端首页", tags = "阿姨端首页")
public class AuntHomeController {

    private final JazSysBannerService jazSysBannerService;

    private final AuntHomeService auntHomeService;

    private final JazSysProjectService jazSysProjectService;

    private final JazMessageService jazMessageService;

    private final JazUserOrderService jazUserOrderService;

    public AuntHomeController(JazSysBannerService jazSysBannerService,AuntHomeService auntHomeService,JazSysProjectService jazSysProjectService,JazMessageService jazMessageService,JazUserOrderService jazUserOrderService){
        this.jazSysBannerService = jazSysBannerService;
        this.auntHomeService = auntHomeService;
        this.jazSysProjectService = jazSysProjectService;
        this.jazMessageService = jazMessageService;
        this.jazUserOrderService = jazUserOrderService;
    }

    @ApiOperation(value = "banner轮播图", notes = "banner轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "size", value = "size", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "curren", value = "curren", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "position", value = "position", required = true, dataType = "Integer"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/bannerList")
    public Result<List<JazSysBannerDO>> list(JazSysBannerDO jazSysBannerDTO){
        // 查询列表数据
        Wrapper<JazSysBannerDO> jazSysBannerDOWrapper = new EntityWrapper<JazSysBannerDO>().orderBy("sort", true).orderBy("id", false);
        if(null!=jazSysBannerDTO.getPosition()){
            jazSysBannerDOWrapper.eq("position",jazSysBannerDTO.getPosition());
        }
        List<JazSysBannerDO> list = jazSysBannerService.selectList(jazSysBannerDOWrapper);
        return Result.ok(list);
    }


    @ApiOperation(value = "需求分页列表查询", notes = "需求分页列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "服务类型id", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "age", value = "年龄", required = false, dataType = "String"),
            @ApiImplicitParam(name = "salary", value = "薪资待遇", required = false, dataType = "BigDecimal"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "curren", value = "当前页", required = true, dataType = "Integer"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/selUserDemandList")
    public Result<?> selUserDemandList(String projectId,String age,String salary,int current, int size){

        return auntHomeService.selUserDemandList(projectId,age,salary,current,size);
    }


    /**
     * 月嫂入驻功能 阿姨招募提交接口
     * @param auntUserVO
     * @return
     */
    @ApiOperation(value = "月嫂入驻功能 阿姨招募提交接口", notes = "月嫂入驻功能 阿姨招募提交接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "auntUserVO", value = "月嫂表单", required = true, dataType = "Object"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/savaUserAunt")
    public Result<?> savaUserAunt(@RequestBody AuntUserVO auntUserVO) throws Exception{

        return auntHomeService.savaUserAunt(auntUserVO);
    }

    @ApiOperation(value = "阿姨首页主要服务查询  8个", notes = "阿姨首页主要服务查询 8个")
    @ApiImplicitParams({

    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/list")
    public Result<List<JazSysProjectDO>> list(){
        Wrapper<JazSysProjectDO> wrapper = new EntityWrapper<>();
        wrapper.eq("status",0); //正常状态
        wrapper.orderBy("sort");
        List<JazSysProjectDO> jazSysProjectDOS = jazSysProjectService.selectList(wrapper);
        jazSysProjectDOS =  jazSysProjectDOS.stream().limit(8).collect(Collectors.toList());  //只要前8个项目
        return Result.ok(jazSysProjectDOS);
    }


    /**
     * 需求详情查询
     * @return
     */
    @ApiOperation(value = "需求详情查询", notes = "需求详情查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "需求列表id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazUserDemandDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/selUserDemandById")
    public Result<?> selUserDemandById(String id){

        return auntHomeService.selUserDemandById(id);
    }


    /**
     * 审核状态查询
     * @return
     */
    @ApiOperation(value = "审核状态查询", notes = "审核状态查询")
    @ApiImplicitParams({

    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/isUserAunt")
    public Result<?> isUserAunt(){

        return auntHomeService.isUserAunt();
    }


    /**
     * 判断是否签约
     * auntId：月嫂id
     * @return
     */
    @ApiOperation(value = "判断是否签约", notes = "判断是否签约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "auntUserId", value = "月嫂id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "senderId", value = "消息发送者id（接单人id）", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "receiverId", value = "消息接收者id（sysUserId）", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "demandId", value = "媒介id（需求id）", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazUserOrderDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/isContract")
    public Result<?> isContract(String auntUserId,Long senderId,Long receiverId,Long demandId){


        return auntHomeService.isContract(auntUserId,senderId,receiverId,demandId);
    }

    /**
     *
     * 我要接单（发送接单消息给用户端）
     * @return
     */
    @ApiOperation(value = "我要接单（发送接单消息给用户端）", notes = "我要接单（发送接单消息给用户端）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "senderId", value = "消息发送者id（接单人id）", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "receiverId", value = "消息接收者id（sysUserId）", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "objectId", value = "媒介id（需求id）", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazMessageDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/takingOrders")
    public Result<?> takingOrders(Long senderId,Long receiverId,Long objectId){

        return auntHomeService.takingOrders(senderId,receiverId,objectId);
    }

    /**
     * 月嫂简历信息回显
     * @return
     */
    @ApiOperation(value = "月嫂简历信息回显", notes = "月嫂简历信息回显")
    @ApiImplicitParams({

    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = AuntUserVO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/selUserAunt")
    public Result<?> selUserAunt(){

        return auntHomeService.selUserAunt();
    }

    /**
     * 可用标签下拉框查询
     * @return
     */
    @ApiOperation(value = "可用标签下拉框查询", notes = "可用标签下拉框查询")
    @ApiImplicitParams({

    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazSysLabelDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/sleLabel")
    public Result<?> sleLabel(){
        return auntHomeService.sleLabel();
    }


    /**
     * 获取用户信息
     * @return
     */
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = UserDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/getUserInfo")
    public Result<?> getUserInfo(String token){

        return auntHomeService.getUserInfo(token);
    }

    /**
     * 判断阿姨招募是否能填写
     * true:可以
     * false:不可以
     * @return
     */
    @ApiOperation(value = "判断阿姨招募是否能填写(true:可以,false:不可以)", notes = "判断阿姨招募是否能填写(true:可以,false:不可以)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "auntId", value = "阿姨id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = UserDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/getIsEdit")
    public Result<?> getIsEdit(Long auntId){

        return auntHomeService.getIsEdit(auntId);
    }


    /**
     * 阿姨端查询订单详情
     * @return
     */
    @ApiOperation(value = "阿姨端查询订单详情", notes = "阿姨端查询订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "Long"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = UserDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @GetMapping("/auntOrderDetail")
    public Result<?> auntOrderDetail(Long id){

        return Result.ok(jazUserOrderService.auntOrderDetail(id));
    }






}
